use axum::http::StatusCode;
use axum::Json;
use axum::response::{IntoResponse, Response};
use serde_json::json;
use thiserror::Error;

/// 登录错误
#[derive(Debug, Error)]
pub enum LoginError {
    #[error("账号或密码错误")]
    UserOrPassword,
}

impl IntoResponse for LoginError {
    fn into_response(self) -> Response {
        let status = match self {
            LoginError::UserOrPassword => StatusCode::UNAUTHORIZED,
        };

        let body = Json(json!({
            "error": self.to_string(),
            "code": status.as_u16(),
        }));


        (status, body).into_response()
    }
}